package cn.edu.ctbu.studentmanage.service.impl;

import cn.edu.ctbu.studentmanage.domain.Student;
import cn.edu.ctbu.studentmanage.domain.Teacher;
import cn.edu.ctbu.studentmanage.repository.TeacherRepository;
import cn.edu.ctbu.studentmanage.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherImplService  implements TeacherService {
    @Autowired
    private TeacherRepository teacherRepository;
    /**
     * 查询所有教师信息
     * @return
     */
    public List<Teacher> findAll(){

        return teacherRepository.findAll();
    }
    /**
     * 根据教师学号查询教师
     * @param tno
     * @return
     */
    public  Teacher findByTno(String tno){
        return teacherRepository.findTeacherByTno(tno);
    }
    /**
     * 根据教师学号和教师密码查询教师
     * @param tno
     * @param tpassword
     * @return
     */
    public List<Teacher> findByTnoAndTpassword(String tno, String tpassword){

        List<Teacher> Teachers =  teacherRepository.findByTnoAndTpassword(tno,tpassword);

        return Teachers;

    }
    /**
     * 分页
     * @param pageable
     * @return
     */
    public Page<Teacher> findAll(Pageable pageable) {

        return teacherRepository.findAll(pageable);
    }
    /**
     * 分页加动态查询
     * @param teacherExample
     * @param pageable
     * @return
     */
    public Page<Teacher> findAll(Example<Teacher> teacherExample, Pageable pageable){
        return teacherRepository.findAll(teacherExample,pageable);
    }
    /**
     * 根据id获取某一教师信息
     * @param tid
     * @return
     */
    public Teacher getByTid(Integer tid){

        return teacherRepository.findById(tid).orElse(null);
    }
    /**
     * 更新教师信息
     * @param teacher
     */
    public void update(Teacher teacher){
        teacherRepository.save(teacher);
    }
    /**
     * 根据id删除某一教师
     * @param tid
     */
    public void delete(Integer tid){
        teacherRepository.deleteById(tid);
    }
    /**
     * 插入新的教师
     * @param teacher
     */
    public void Insert(Teacher teacher){
        teacherRepository.save(teacher);
    }

}
